﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using RBS.Common;
using RBS.Core.Model;
namespace RBS.Core.BLL
{
    //V_OrderDept
    public partial class V_OrderDept
    {

        private readonly RBS.Core.DAL.V_OrderDept dal = new RBS.Core.DAL.V_OrderDept();
        public V_OrderDept()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {
            return dal.Exists(Id, OrderId, HCId, cName, Num, Price, State, OperateDate, CategoryName, HotelId, RoleName, roleid, DineTable, Dinecondition, DineTableName);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(RBS.Core.Model.V_OrderDept model)
        {
            dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(RBS.Core.Model.V_OrderDept model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {

            return dal.Delete(Id, OrderId, HCId, cName, Num, Price, State, OperateDate, CategoryName, HotelId, RoleName, roleid, DineTable, Dinecondition, DineTableName);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RBS.Core.Model.V_OrderDept GetModel(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {

            return dal.GetModel(Id, OrderId, HCId, cName, Num, Price, State, OperateDate, CategoryName, HotelId, RoleName, roleid, DineTable, Dinecondition, DineTableName);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public RBS.Core.Model.V_OrderDept GetModelByCache(int Id, int OrderId, int HCId, string cName, int Num, decimal Price, int State, DateTime OperateDate, string CategoryName, int HotelId, string RoleName, int roleid, int DineTable, string Dinecondition, string DineTableName)
        {

            string CacheKey = "V_OrderDeptModel-" + Id + OrderId + HCId + cName + Num + Price + State + OperateDate + CategoryName + HotelId + RoleName + roleid + DineTable + Dinecondition + DineTableName;
            object objModel = RBS.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(Id, OrderId, HCId, cName, Num, Price, State, OperateDate, CategoryName, HotelId, RoleName, roleid, DineTable, Dinecondition, DineTableName);
                    if (objModel != null)
                    {
                        int ModelCache = RBS.Common.ConfigHelper.GetConfigInt("ModelCache");
                        RBS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (RBS.Core.Model.V_OrderDept)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<RBS.Core.Model.V_OrderDept> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<RBS.Core.Model.V_OrderDept> DataTableToList(DataTable dt)
        {
            List<RBS.Core.Model.V_OrderDept> modelList = new List<RBS.Core.Model.V_OrderDept>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                RBS.Core.Model.V_OrderDept model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new RBS.Core.Model.V_OrderDept();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["HotelId"].ToString() != "")
                    {
                        model.HotelId = int.Parse(dt.Rows[n]["HotelId"].ToString());
                    }
                    model.RoleName = dt.Rows[n]["RoleName"].ToString();
                    if (dt.Rows[n]["roleid"].ToString() != "")
                    {
                        model.roleid = int.Parse(dt.Rows[n]["roleid"].ToString());
                    }
                    if (dt.Rows[n]["DineTable"].ToString() != "")
                    {
                        model.DineTable = int.Parse(dt.Rows[n]["DineTable"].ToString());
                    }
                    model.Dinecondition = dt.Rows[n]["Dinecondition"].ToString();
                    model.DineTableName = dt.Rows[n]["DineTableName"].ToString();
                    if (dt.Rows[n]["OrderId"].ToString() != "")
                    {
                        model.OrderId = int.Parse(dt.Rows[n]["OrderId"].ToString());
                    }
                    if (dt.Rows[n]["HCId"].ToString() != "")
                    {
                        model.HCId = int.Parse(dt.Rows[n]["HCId"].ToString());
                    }
                    model.cName = dt.Rows[n]["cName"].ToString();
                    if (dt.Rows[n]["Num"].ToString() != "")
                    {
                        model.Num = int.Parse(dt.Rows[n]["Num"].ToString());
                    }
                    if (dt.Rows[n]["Price"].ToString() != "")
                    {
                        model.Price = decimal.Parse(dt.Rows[n]["Price"].ToString());
                    }
                    if (dt.Rows[n]["State"].ToString() != "")
                    {
                        model.State = int.Parse(dt.Rows[n]["State"].ToString());
                    }
                    if (dt.Rows[n]["OperateDate"].ToString() != "")
                    {
                        model.OperateDate = DateTime.Parse(dt.Rows[n]["OperateDate"].ToString());
                    }
                    model.CategoryName = dt.Rows[n]["CategoryName"].ToString();


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion


        #region  ExtensionMethod
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }

        #endregion  ExtensionMethod

    }
}